﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
namespace SchoolManagementSystem.Details
{
    public partial class Subject_TeacherUC : DetailUC
    {
        public Subject_TeacherUC()
        {
            InitializeComponent();
            this.ObjectName = "môn học";
            this.Code = "Subject_Teacher";
            this.Type = new Subject_Teacher();

            comboboxUC_teacher.Model = RegisterService.RegisterServices.TeacherService;
            comboboxUC_teacher.Uc = new TeacherUC();
            comboboxUC_teacher.ColumnMain = "Name";
            comboboxUC_teacher.ColumnDisplay = "Code,Name";


        }

       
        protected override long DetailDisplay()
        {
            Subject_Teacher data = new Subject_Teacher();
            if (ID > 0)
            {
                data = (Subject_Teacher)RegisterService.RegisterServices.SubjectTeacherService.GetByID(ID);
               
            }

            comboboxUC_teacher.ID = data.TeacherID;
            return ID;

        }

        protected override long Save()
        {
            Subject_Teacher data = new Subject_Teacher();
            if (ID > 0)
            {
                data = (Subject_Teacher)RegisterService.RegisterServices.SubjectTeacherService.GetByID(ID);

            }

            data.TeacherID = comboboxUC_teacher.ID;
            data.SubjectID = long.Parse(SearchString.Replace("'", "").Replace("SubjectID=", "").Trim());

            ID = RegisterService.RegisterServices.SubjectTeacherService.Save(data);
           
            return ID;
        }


        public override bool Delete(long SelectedID)
        {

           // return RegisterService.RegisterServices.SubjectTeacherService.Delete(RegisterService.RegisterServices.SubjectTeacherService.GetByID(SelectedID));
            return RegisterService.RegisterServices.SubjectTeacherService.UpdateIsDelete(RegisterService.RegisterServices.SubjectTeacherService.GetByID(SelectedID));
        }

        private void comboboxUC_teacher_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }

    }
}
